/*************************************************************************
	> File Name: stu_overload.cc
	> Author: likang
	> Mail:  
	> Created Time: 2015年01月07日 星期三 16时01分45秒
 ************************************************************************/

#include<iostream>
using namespace std;

class Stu {
public:
	Stu(int age1, string name1): age(age1), name(name1) {}
	Stu() {}
	int get_age() const { return age;}
	string get_name() const { return this->name;}
	friend ostream& operator<<(ostream&, const Stu&);
	friend istream& operator>>(istream&, Stu&);
	Stu& operator+=(const Stu&);
	friend Stu operator+(const Stu&, const Stu&);
	Stu& operator++();
	Stu& operator++(int);
private:
	int age;
	string name;
};

Stu& Stu::operator++() {
	++age;
	return *this;
}

Stu& Stu::operator++(int) {
	Stu ret(*this);
	++*this;
	return ret;
}

ostream& operator<<(ostream& out, const Stu& s) {
	out <<  s.age << ": " << s.name;
	return out;
}

istream& operator>>(istream& in, Stu& s) {
	in >> s.age >> s.name;
	if (in);
	else
		s = Stu(200,"kk");
	return in;
}

Stu& Stu::operator+=(const Stu& s) {
	age += s.age;
	name += s.name;
	return *this;
}

Stu operator+(const Stu& s1, const Stu& s2) {
	Stu s(s1);
	s += s2;
	return s;
}


int main(void) {

	Stu s(100,"kiss");
	cout << "s:" << s << endl;
	Stu s1;
	cin >> s1;
	cout << "s1:" << s1 << endl;
	Stu s2(s + s1);
	cout << "s2:" << s2 << endl;
	s += s1;
	cout << "s:" << s << endl;
	cout << "s:" << s++ << endl;
	cout << "s:" << s << endl;
	return 0;
}
